package com.dqp.cslggroup.JWXT;

import com.dqp.cslggroup.UI.MyApplication;
import com.dqp.cslggroup.Util.SharedPreferencesUtil;

import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

import java.io.IOException;
import java.util.Map;

public class GetHeadPortrait {
    private String url;
    private Connection.Response response;
    private Document document;
    private Map<String, String> cookies;
    private String stuNum;
    private String Authorization = SharedPreferencesUtil.getStringSp(MyApplication.getContext(), "Authorization", "");

    public GetHeadPortrait(String url, Map<String, String> cookies, String sno) {
        this.url = url;
        this.cookies = cookies;
        this.stuNum = sno;
    }

    byte[] getPic() throws IOException {
        response = Jsoup.connect(url + "/jwglxt/xtgl/photo_cxXszp.html?xh_id=" + stuNum + "&zplx=rxhzp")
                .ignoreContentType(true) // 获取图片需设置忽略内容类型
                .userAgent("Mozilla")
                .header("Authorization", Authorization)
                .cookies(cookies)
                .method(Connection.Method.GET)
                .timeout(5000)
                .execute();
        return response.bodyAsBytes();
    }

    public String getXl() throws Exception {
        response = Jsoup.connect(url + "/jwglxt/xtgl/index_cxAreaFive.html?localeKey=zh_CN&gnmkdm=index&su=" + stuNum)
                .header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36")
                .cookies(cookies)
                .header("Authorization", Authorization)
                .timeout(5000)
                .method(Connection.Method.GET)
                .ignoreContentType(true)
                .execute();
        document = Jsoup.parse(response.body());
        return document.select("th[colspan=23]").text();
    }


}
